package entitiesfactory;

import java.lang.reflect.Type;
import java.util.HashMap;

import workerswithdb.IDAOWorker;
import api.controller.IAutoservice;
import api.entitites.IGarage;
import api.entitites.IMaster;
import api.entitites.IOrder;
import api.exportimportentities.IExportImportEntities;


public class EntitiesFactory {
	private String NOT_FOUND = "This type not found";
	private String NOT_OBJECT = "This object not create";
	private HashMap<Class, String> classMap = new HashMap<Class, String>();
	private static EntitiesFactory entitiesFactory;

	private EntitiesFactory() {
		classMap.put(IAutoservice.class, "controllers.Autoservice");
		classMap.put(IExportImportEntities.class,"exportimporterentities.ExportImportEntities");
		classMap.put(IDAOWorker.class, "dao.daocontrollers.DAOWorker");
		classMap.put(IGarage.class, "entities.Garage");
		classMap.put(IMaster.class, "entities.Master");
		classMap.put(IOrder.class, "entities.Order");		

	}

	public static EntitiesFactory getInstance() {
		if (entitiesFactory == null) {
			entitiesFactory = new EntitiesFactory();
		}
		return entitiesFactory;
	}

	public Object getObject(Type cInterface) {
		try {
			String className = classMap.get(cInterface);
			Class currentClass = Class.forName(className);
			//return currentClass.newInstance();*/
			return currentClass;
		}catch (ClassNotFoundException clex) {
			clex.printStackTrace();
			throw new RuntimeException(NOT_FOUND);
		} catch (Exception e) {
			throw new RuntimeException(NOT_OBJECT);
		}
	}

}
